class Solution {
public:
    int maxDepth(TreeNode* root) {
        if (!root) return 0;
        else 
            return max(maxDepth(root->left), maxDepth(root->right)) + 1;
    }

    int maxDepth_1(TreeNode* root) {
        if (!root) return 0;
        int result = 0;
        queue<TreeNode *> q;
        q.push(root);
        while (!q.empty()) {
            result++;           
            int size = q.size();
            for (int i = 0; i < size; ++i) {
                TreeNode *node = q.front();
                q.pop();
                if (node->left) q.push(node->left);
                if (node->right) q.push(node->right);
            }
        }
        return result;
    }
};